<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- android.qdoc -->
  <title>Android Services | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Android Services</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Android Services</h1>
<span class="subtitle"></span>
<!-- $$$android-services.html-description -->
<div class="descr"> <a name="details"></a>
<p>Starting with Qt 5.7, you can create Android services using Qt. A service is a component that runs in background, so, it has no user interface. It is useful to perform long-term operations such as logging GPS, waiting for social media notifications, and so on. A service will continue to run even if the application that started it exits.</p>
<p>To create a service, do the following steps:</p>
<ol class="1" type="1"><li>Uncomment the service part of your <code>AndroidManifest.xml</code>.</li>
<li>Make sure the <code>service</code> tag contains an <code>android:process=&quot;:some_name&quot;</code> attribute. It is needed to force the <code>service</code> to run in a separate process than the <code>activity</code>.</li>
<li>If you're using the same application (.so file) for activity and also for service, you need to use <code>android.app.arguments</code> <code>meta-data</code> to pass some arguments to your <code>main</code> function in order to know which one is which.</li>
<li>To enable background running, uncomment <code>android.app.background_running</code> <code>meta-data</code> and set it to true (<code>android:value=&quot;true&quot;</code> ).</li>
</ol>
<p>Qt loads the <code>.so</code> file defined in <code>android.app.lib_name</code> <code>meta-data</code>, and calls the <code>main</code> function with all the arguments set in <code>android.app.arguments</code> <code>meta-data</code>.</p>
<p>See <a href="http://developer.android.com/guide/components/services.html">Android Services</a> documentation for more information.</p>
</div>
<!-- @@@android-services.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
